#include<cstdio>
#include<cstring>
using namespace std;
int n,i,j,c,comlist[1001];
char op[10],ad[30],adlist[1001][30];
int getint(const char* m,int biggermax=0)
{
	int i,a;
	if(m[0]=='0'&&m[1]>='0'&&m[1]<='9')
	return -1;
	if(m[0]=='0')
	return 1;
	if(m[0]>'9'||m[0]<'0')
	return -1;
	a=m[0]-'0';
	for(i=1;m[i]>='0'&&m[i]<='9';i++)
	{
		a=a*10+m[i]-'0';
		if(a>100000)
		break;
	}
	if(a<=255)
	return 1;
	if(biggermax==1&&a<=65535)
	return 1;
	return -1;
}
int rightads(const char* p)
{
	int a,b,c,d,e,i;
	if(getint(p)==-1)
	return 0;
	for(i=0;p[i]>='0'&&p[i]<='9';i++);
	if(p[i]!='.')
	return 0;
	i++;
	if(getint(p+i)==-1)
	return 0;
	for(;p[i]>='0'&&p[i]<='9';i++);
	if(p[i]!='.')
	return 0;
	i++;
	if(getint(p+i)==-1)
	return 0;
	for(;p[i]>='0'&&p[i]<='9';i++);
	if(p[i]!='.')
	return 0;
	i++;
	if(getint(p+i)==-1)
	return 0;
	for(;p[i]>='0'&&p[i]<='9';i++);
	if(p[i]!=':')
	return 0;
	i++;
	if(getint(p+i,1)==-1)
	return 0;
	for(;p[i]>='0'&&p[i]<='9';i++);
	if(p[i]!=0)
	return 0;
	return 1;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s %s",op,ad);
		if(op[0]=='S')
		{
			if(rightads(ad)==0)
			printf("ERR\n");
			else
			{
				for(j=1;j<=c;j++)
				if(strcmp(ad,adlist[j])==0)
				break;
				if(j<=c)
				printf("FAIL\n");
				else
				{
					printf("OK\n");
					c++;
					comlist[c]=i;
					strcpy(adlist[c],ad);
				}
			}
		}
		else
		{
			if(rightads(ad)==0)
			printf("ERR\n");
			else
			{
				for(j=1;j<=c;j++)
				if(strcmp(ad,adlist[j])==0)
				break;
				if(j>c)
				printf("FAIL\n");
				else
				printf("%d\n",comlist[j]);
			}
		}
	}
	return 0;
}
